# vPresent is an immersive presentation creation and display application.
# Copyright (C) 2007-2009 by Priority 5 Holdings, Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from PyQt4 import QtCore, QtGui

import math
import gmtl
import navstatusui


class NavStatus(QtGui.QFrame, navstatusui.Ui_Form):
   def __init__(self, parent = None):
      QtGui.QFrame.__init__(self, parent)
      self.setupUi(self)

   def setupUi(self, form):
      navstatusui.Ui_Form.setupUi(self, form)
      self.setFrameShadow(QtGui.QFrame.Sunken)

   def setPosition(self, x, y, z):
      self.posText.setText("%f, %f, %f" % (x, y, z))

   def setRotation(self, h, p, r):
      self.rotText.setText("H:%f P:%f R:%f" % (h, p, r))

   def refresh(self, navMatrix):
      '''
      navMatrix must be of type osg.Matrix
      '''
      
      nav_mat = gmtl.Matrix44f()
      nav_mat.set(navMatrix.getValues())
      trans_vec = gmtl.makeTransVec3(nav_mat)
      rot_angles = gmtl.makeRotEulerAngleXYZ(nav_mat)
      self.setPosition(trans_vec[0], trans_vec[1], trans_vec[2])
      self.setRotation(math.degrees(rot_angles[1]),
                       math.degrees(rot_angles[0]),
                       math.degrees(rot_angles[2]))
